import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle
} from '@/components/ui/alert-dialog'
import { useGlobalStore } from '@/lib/use-global-store'
const AlertDialogProvider = () => {
  const { alertOpen, alertConfig, updateAlertOpen } = useGlobalStore()
  const handleConfirm = () => {
    if (alertConfig?.onConfirm) {
      alertConfig.onConfirm()
    }
    updateAlertOpen(false)
  }

  const handleCancel = () => {
    if (alertConfig?.onCancel) {
      alertConfig.onCancel()
    }
    updateAlertOpen(false)
  }

  return (
    <AlertDialog open={alertOpen}>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>{alertConfig?.title || '需要确认'}</AlertDialogTitle>
          <AlertDialogDescription>{alertConfig?.description || '您确定要执行此操作吗?'}</AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel onClick={handleCancel}> {alertConfig?.cancelLabel || '取消'}</AlertDialogCancel>
          <AlertDialogAction onClick={handleConfirm}> {alertConfig?.confirmLabel || '确认'}</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  )
}

export { AlertDialogProvider }
